//
//  AAAViewController.m
//  IOSwork
//
//  Created by  liuzechao on 15/8/14.
//  Copyright (c) 2015年 mohekeji. All rights reserved.
//

#import "AAAViewController.h"
#import "OneViewController.h"
#define heigth 59
#define IP 123456778
@interface AAAViewController ()
<UIAlertViewDelegate>
@end

@implementation AAAViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSUserDefaults standardUserDefaults]setValue:@"张三" forKey:@"name"];
    [[NSUserDefaults standardUserDefaults]removeObjectForKey:@"name"];
    NSString*III;
    int a=1;
    int b=2;
    III = a>b?@"大于":@"小于";

    _BBB=@[@{@"header":@"A",@"footer":@"共两位",@"image":@"2",@"list":@[@{@"title":@"鞍山:1234567"},@{@"title":@"安庆:1234566"}]},@{@"header":@"B",@"footer":@"共两位",@"image":@"2",@"list":@[@{@"title":@"班山:2234567"},@{@"title":@"笔庆:1254566"}]},@{@"header":@"C",@"footer":@"共两位",@"image":@"2",@"list":@[@{@"title":@"成都:2244567"},@{@"title":@"长春:1654566"}]},@{@"header":@"D",@"footer":@"共两位",@"image":@"2",@"list":@[@{@"title":@"大连:2244567"},@{@"title":@"大庆:1676566"}]}];
    

    // Do any additional setup after loading the view from its nib.
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}
- (void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    NSDictionary*dic=[_BBB objectAtIndex:section];
    
    NSArray*arr=dic[@"list"];
    
    return arr.count;
    
}

-(UITableViewCell  *)tableView:(UITableView *)tableView

         cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *CellIdentifier = @"Cell";
    
    
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    
    
    
    if (cell == nil) {
        
        
        
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
        
        
        
    }
    
    NSDictionary*dicOne=[_BBB objectAtIndex:indexPath.section];
    
    NSArray*arr=dicOne[@"list"];
    
    NSDictionary*dicTwo=[arr objectAtIndex:indexPath.row];
    
    
    
    cell.textLabel.text = [dicTwo objectForKey:@"title"];
    
    return cell;
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    
    return _BBB.count;
    
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{return heigth;}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{return heigth;}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{return heigth;}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    
    UIView*view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 59)];
    
    view.backgroundColor=[UIColor yellowColor];
    
    UILabel*lable=[[UILabel alloc]initWithFrame:CGRectMake(10, 10, 200, 21)];
    
    NSDictionary *dicThree=[_BBB objectAtIndex:section];
    
    lable.text=dicThree[@"header"];
    
    [view addSubview:lable];
    
    UIImageView*CCC=[[UIImageView alloc]initWithFrame:CGRectMake(290, 24, 21, 21)];
    
    CCC.image=[UIImage imageNamed:dicThree[@"image"]];
    
    [view addSubview:CCC];
    
    return view;
    
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{UIView*view01=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 59)];
    
    view01.backgroundColor=[UIColor redColor];
    
    UILabel*lable01=[[UILabel alloc]initWithFrame:CGRectMake(10, 10, 200, 21)];
    
    NSDictionary *dicFour=[_BBB objectAtIndex:section];
    
    lable01.text=dicFour[@"footer"];
    
    [view01 addSubview:lable01];
    
    return view01;
    
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    OneViewController *vc = [[OneViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];UIAlertView*HHH=[[UIAlertView alloc]initWithTitle:@"提示" message:@"确认要退出吗？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确认", nil];
    [HHH show];}
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    if (buttonIndex==0) {NSLog(@"拜拜");}
    else  {NSLog(@"确认取消吗");}
}




@end
